﻿using System;
using System.Linq;
using System.Web.Mvc;
using Project.Common;
using System.Collections.Generic;
using Project.Web.Base;
using OASys.Biz.BizAccess;
using OASys.Web.Models;
using Project.Web.Base.Utility;

namespace OASys.Web.Controllers
{
	/// <summary>
	/// 供应商管理
	/// </summary>
	public class SampleController : BaseController
	{
		private BizUTSample bizUTSupplier;
		/// <summary>
		/// 供应商信息列表显示
		/// </summary>
		/// <param name="modelUTSupplierManage"></param>
		/// <returns></returns>
		public ActionResult Index(ModelSampleIndex model,ExportHelper export)
		{
			model.ExportObject = export;
			model.RetriveData();
			return View(model);
		}

		public ActionResult Create(Guid? id, EnumPageState? pageState)
		{
			ViewBag.PageState = GetPageState(id, pageState);
			if (id != null)
			{
				//修改供应商信息
				ModelSampleCreate model = new ModelSampleCreate();
				model.UTSample = bizUTSupplier.GetByID<Guid>(id.Value);
				return View(model);
			}
			return View();
		}

		/// <summary>
		/// 新增供应商信息
		/// </summary>
		/// <param name="modelUTSupplierManage"></param>
		/// <returns></returns>
		[HttpPost]
		public ActionResult Create(ModelSampleCreate model)
		{
			try
			{
				model.Save();
                return Content(WebTools.ScriptCloseDialog(DialogOption.GetDefaultInstance()));
			}
			catch
			{
				Error = "操作失败";
				ViewBag.PageState = PageState;
				return View(model);
			}
		}

		/// <summary>
		/// 删除供应商信息
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPost]
		public ActionResult Delete(Guid id)
		{
			JsonResult jsresult = new JsonResult();
			jsresult.ContentType = Consts.CONTENT_TYPE;
			try
			{
				bizUTSupplier.DeleteByID(id, NHibernate.NHibernateUtil.Guid);
				jsresult.Data = new { result = string.Empty };
			}
			catch
			{
				jsresult.Data = new { result = "操作失败" };
			}
			return jsresult;
		}

	}
}